<?php
class Admin_Model_DbTable_hotel extends Zend_Db_Table_Abstract
{
	protected $_name="hae_hotel";
	protected $_primary="id";
	protected $_sequence=true;
	protected $_referenceMap=array(
	"city"=> array(
		'columns'=>array('cityId'),
		'refTableClass'=>'Admin_Model_DbTable_city',
		'refColumns'=>array('id'),
		'onDelete'=>self::RESTRICT,
		'onUpdate'=>self::RESTRICT
	)
	);
	public function getHotel($id)
	{
		try {
			$row = $this->find($id)->current();
			return $row;
		}catch(Zend_Exception $e)
		{
			echo $e->getMessage();
		}
	}
	public function getList()
	{
		try {
			$select=$this->select();
			$select->from($this->_name,array("id","name","address","cityId","priority","rate"));
			return  $this->fetchAll($select);
			
		}catch(Zend_Exception $e)
		{
			echo $e->getMessage();
		}
	}
	//get by city and name of hotel.
	public function getBy($id, $name)
	{
		try {
			$select = $this->select();
			$select->from($this->_name,array("id","name","address","cityId","priority","rate"));
			$select->where("cityId = ?",$id);
			$select->where("name like ?", "%".$name."%");
			return $this->fetchAll($select);
		}catch(Zend_Exception $e)
		{
			
		}
	}
	public function updateHotel($id, $name, $address, $website, $priority, $rate,$cityId, $desc_vi, $desc_en, $desc_ja, $desc_cn, $desc_fr, $accomodation, $service, $tour, $meeting)
	{
		try {
			$row=$this->find($id)->current();
			$row->name=$name;
			$row->address=$address;
			$row->website=$website;
			$row->priority=$priority;
			$row->rate=$rate;
			$row->cityId=$cityId;
			$row->desc_vi=$desc_vi;
			$row->desc_en=$desc_en;
			$row->desc_ja=$desc_ja;
			$row->desc_cn=$desc_cn;
			$row->desc_fr=$desc_fr;
			$row->accomodation=$accomodation;
			$row->service=$service;
			$row->tour=$tour;
			$row->meeting=$meeting;
			if($row->save()>0) return true;
			else return false;
		}catch(Zend_Exception $e)
		{
			echo $e->getMessage();
		}
	}
	public function addHotel($name, $address, $website, $priority, $rate,$cityId, $desc_vi, $desc_en, $desc_ja, $desc_cn, $desc_fr, $accomodation, $service, $tour, $meeting)
	{
		try {
			$row=$this->createRow();
			$row->name=$name;
			$row->address=$address;
			$row->website=$website;
			$row->priority=$priority;
			$row->rate=$rate;
			$row->cityId=$cityId;
			$row->desc_vi=$desc_vi;
			$row->desc_en=$desc_en;
			$row->desc_ja=$desc_ja;
			$row->desc_cn=$desc_cn;
			$row->desc_fr=$desc_fr;
			$row->accomodation=$accomodation;
			$row->service=$service;
			$row->tour=$tour;
			$row->meeting=$meeting;
			if($row->save()>0 ) return true;
			return false;
		}catch(Zend_Exception $e)
		{
			echo $e->getMessage();
		}
	}
	public function delhotel($id)
	{
		try {
			$row= $this->find($id)->current();
			if($row->delete() >0 ) return true;
			else return false;
			
		}catch(Zend_Exception $e)
		{
			echo $e->getMessage();
		}
	}
}